package com.handpay.zztong.hp.main.model;

import android.content.Context;
import android.text.TextUtils;

import com.handpay.zztong.hp.accountcenter.activity.BankCardManagerActivity;
import com.handpay.zztong.hp.accountcenter.activity.BaseInfoActivity;
import com.handpay.zztong.hp.db.ormlite.DataBaseComponentModel;
import com.handpay.zztong.hp.main.model.component.ComponentItemBean;
import com.handpay.zztong.hp.onlineshop.activity.JieAnHtmlActivity;
import com.handpay.zztong.hp.smartpay.activity.IntrePaymentHtmlActivity;
import com.handpay.zztong.hp.swiper.activity.ConnectSwiperActivity;
import com.handpay.zztong.hp.qualification.activity.IDCardateActivity;
import com.handpay.zztong.hp.ShowLoanHtmlActivity;
import com.handpay.zztong.hp.main.activity.AllFunctionActivity;
import com.handpay.zztong.hp.main.activity.MainActivity;
import com.handpay.zztong.hp.notification.activity.NoticeActivity;
import com.handpay.zztong.hp.accountcenter.activity.QualificationInfoActivity;
import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.ScannerCodePayActivity;
import com.handpay.zztong.hp.other.activity.ShowHtmlActivity;
import com.handpay.zztong.hp.onlineshop.activity.ShowMarketHtmlActivity;
import com.handpay.zztong.hp.SuperTransferAccounts;
import com.handpay.zztong.hp.qualification.activity.T0QualificationActivity;
import com.handpay.zztong.hp.accountcenter.activity.TransferCashLimitManagementActivity;
import com.handpay.zztong.hp.paymentbill.activity.QueryBillsActivity;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * 主界面显示的组建
 *
 * @author dlfeng
 *         2015/5/14
 */
public class FunctionInfo {


    public static final String COLLECT_MONEY_ICON_CODE = "collect_money";
    public static final String SCAN_PAYMENT_ICON_CODE = "scan_payment";
    public static final String MONG_HOO_ICON_CODE = "mong_hoo";
    public static final String HONG_SHOP_ICON_CODE = "hong_shop";
    public static final String LOAN_PACKAGE_ICON_CODE = "loan_package";
    public static final String STOCK_FUND_ICON_CODE = "stock_fund";
    public static final String QQ_IM_ICON_CODE = "qq_im";
    public static final String GATHER_APP_ICON_CODE = "gather_app";
    public static final String JIEAN_ICON_CODE = "jiean_dai";
    public static final String MOBILE_RECHARGE_ICON_CODE = "mobile_recharge";
    public static final String LOAN_ICON_CODE = "loan_dai";
    public static final String FAST_TRANSFER_ICON_CODE = "fast_transfer";
    public static final String CREDIT_CARD_ICON_CODE = "credit_card";
    public static final String NO_CARD_PAYMENT_ICON_CODE = "nocard_payment";
    public static final String QR_CODE_ICON_CODE = "qrcode_payment";
    public static final String INTRE_PAYMENT_ICON_CODE = "intre_payment";

    public static final String COLLECT_MONEY_CODE = "collectMoney";
    public static final String SCAN_PAYMENT_CODE = "scanPayment";
    public static final String MONG_HOO_CODE = "mongHoo";
    public static final String HONG_SHOP_CODE = "onlineMarket";
    public static final String LOAN_PACKAGE_CODE = "loanPackage";
    public static final String STOCK_FUND_CODE = "stockFund";
    public static final String QQ_IM_CODE = "qqIm";
    public static final String GATHER_APP_CODE = "gatherApp";
    public static final String JIEAN_CODE = "jieAn";
    public static final String MOBILE_RECHARGE_CODE = "mobileRecharge";
    public static final String LOAN_CODE = "loan";
    //    快速转账
    public static final String FAST_TRANSFER_CODE = "fastTransfer";
    public static final String CREDIT_CARD_CODE = "creditCard";
    public static final String NO_CARD_PAYMENT_CODE = "noCardPayment";
    public static final String QR_CODE_CODE = "qrcodePayment";
    public static final String MY_BASIC_INFO_CODE = "basicinfo";
    public static final String MY_QUALIFICATION_INFO_CODE = "qualificationinfo";
    public static final String MY_COLLECT_CARD_MANAGEMENT_CODE = "collectcardmanagement";
    public static final String MY_COLLECT_LIMIT_CODE = "collectlimit";
    public static final String MY_COLLECT_FLOW_CODE = "collectflow";
    public static final String MY_SWIPE_SELECT_CODE = "swipeselect";
    public static final String MY_USER_NOTICE_CODE = "usernotice";
    public static final String MY_T0_QUALIFICATION_CODE = "T0Qualification";
    public static final String MY_ID_Cardate_CODE = "IDCardate";
    //收款提现
    public static final String MY_CollectWithdraw_CODE = "collectwithdraw";
    //智能还款
    public static final String INTRE_PAYMENT_CODE = "intrePayment";


    //刷卡器连接
//    public static final String MY_SwipeSelect_CODE  ="SwipeSelect";
    /*
    0、1、收款        	    CollectMoney
    1、2、快速转账      	FastTransfer
    2、3、信用卡还款	RepaymentCreditcard
    3、4、用户通知		UserNotice
    4、5、话费充值		PrepaidRecharge
    5、6、游戏充值		GameRecharge
    6、7、基本信息		BasicInfo
    7、8、资质信息		QualificationInfo
    8、9、收款卡管理	CollectCardManagement
    9、10、收款限额	CollectLimit
    10、11、收款流水	CollectFlow
    11、12、收款提现	CollectWithdraw
    12、13、刷卡器连接	SwipeSelect
    13、14、微理财                 SmallFinancing
    14、15、Q币充值              QBRecharge
    15、16,TO资质提现      T0Qualification
    16、17,TO卡小宝二维码界面      KXBScanner
    21、股票开户
    22、扫码收款
    23、代还信用卡
    24、贷款
    25、全部应用
    */
//    public static final String[] FUNCTIONID = new String[]{
//            "collectmoney",//0
//            "fasttransfer",//1
//            "repaymentcreditcard",//2
//            "usernotice",//3
//            "prepaidrecharge",//4
//            "gameRecharge",//5
//            "basicinfo",//6
//            "qualificationinfo",//7
//            "collectcardmanagement",//8
//            "collectlimit",//9
//            "collectflow",//10
//            "collectwithdraw",//11
//            "swipeselect",//12
//            "smallfinancing",//13
//            "QBRecharge",//14
//            "T0Qualification",//15
//            "QQConsultation",//16
//            "KXBScanner",//卡小宝17
//            "Shop98",//18
//            "DistributionSystem",//0
//            "IDCardate",//0
//            "OpenAcountAOP",//股票开户
//            "ScannerCodePay",//扫码收款
//            "LoanCreditCard",//代还信用卡
//            "Loan",//贷款
//            "JieAn",//捷安借贷
//            "AllFunction",//全部应用
//    };


    //    public static final String[] FUNCTIONTITLE = new String[]{
//            "刷卡收款",
//            "银联转账",
//            "信用卡还款",
//            "用户通知",
//            "话费充值",
//            "游戏充值",
//            "基本信息",
//            "资质信息",
//            "收款卡管理",
//            "收款限额",
//            "收款流水",
//            "收款提现",
//            "刷卡器连接",
//            "微理财",
//            "Q币充值",
//            "提现资质",
//            "在线咨询",
//            "卡小宝",
//            "98商城",
//            "在线商城",
//            "证件补传",
//            "证券开户",
//            "扫码支付",
//            "代还信用卡",
//            "贷款",
//            "捷安借贷",
//            "全部应用"
//
//    };
//    public static final Class<?>[] FUNCTIONCLS = new Class<?>[]{
//            MainActivity.class,
//            SuperTransferAccounts.class,
//            SuperTransferAccounts.class,
//            NoticeActivity.class,
//            ShowHtmlActivity.class,
//            ShowHtmlActivity.class,
//            BaseInfoActivity.class,
//            QualificationInfoActivity.class,
//            BankCardManagerActivity.class,
//            TransferCashLimitManagementActivity.class,
//            QueryBillsActivity.class,
//            WithdrawActivity.class,
//            ConnectSwiperActivity.class,
//            FinancingAreaActivity.class,
//            ShowHtmlActivity.class,
//            T0QualificationActivity.class,
//            ShowHtmlActivity.class,
//            KxbActivity.class,
//            ShowHtmlActivity.class,
//            ShowMarketHtmlActivity.class,
//            IDCardateActivity.class,
//            ShowHtmlActivity.class,
//            ScannerCodePayActivity.class,
//            ShowLoanHtmlActivity.class,
//            ShowHtmlActivity.class,
//            JieAnHtmlActivity.class,
//            AllFunctionActivity.class,
//    };
    public String itemId;
    public String title;
    public int[] iconResId;
    public String iconUrl;
    public Class<?> cls;
    //    public boolean isCheckSwiper = false;
//    public boolean isStartActivity = true;
//    public int iconIndex = 0;
    public int index;
    public int showModule;
    public String type;

    public FunctionInfo(String itemId, String title, int[] iconResId, Class<?> cls) {
        super();
        this.itemId = itemId;
        this.title = title;
        this.iconResId = iconResId;
        this.cls = cls;
        this.type = "1";
    }

    public FunctionInfo(String itemId, String title, int[] iconResId, Class<?> cls, String type) {
        super();
        this.itemId = itemId;
        this.title = title;
        this.iconResId = iconResId;
        this.cls = cls;
        this.type = type;
    }

    public FunctionInfo(String itemId, String title, int[] iconResId, Class<?> cls, boolean isCheckSwiper, boolean isStartActivity) {
        super();
        this.itemId = itemId;
        this.title = title;
        this.iconResId = iconResId;
        this.cls = cls;
//        this.isCheckSwiper = isCheckSwiper;
//        this.isStartActivity = isStartActivity;
    }


    public static int getDrawableResIdByItemCode(String itemCode) {
        if (itemCode.equals(COLLECT_MONEY_CODE)) {
            return R.drawable.home_icon_receivables;
        } else if (itemCode.equals(SCAN_PAYMENT_CODE)) {
            return R.drawable.home_icon_scanner_code_pay;
        } else if (itemCode.equals(MONG_HOO_CODE)) {
            return R.drawable.loan_credit_icon;
        } else if (itemCode.equals(HONG_SHOP_CODE)) {
            return R.drawable.home_icon_market;
        } else if (itemCode.equals(LOAN_PACKAGE_CODE)) {
            return R.drawable.home_icon_loan_package;
        } else if (itemCode.equals(STOCK_FUND_CODE)) {
            return R.drawable.home_open_account_aop;
        } else if (itemCode.equals(QQ_IM_CODE)) {
            return R.drawable.home_icon_qq_consultation;
        } else if (itemCode.equals(GATHER_APP_CODE)) {
            return R.drawable.home_icon_all_funciton;
        } else if (itemCode.equals(JIEAN_CODE)) {
            return R.drawable.jiean;
        } else if (itemCode.equals(MOBILE_RECHARGE_CODE)) {
            return R.drawable.home_icon_phone_chongzhi;
        } else if (itemCode.equals(LOAN_ICON_CODE)) {
            return R.drawable.home_icon_loan;
        } else if (itemCode.equals(FAST_TRANSFER_CODE)) {
            return R.drawable.home_icon_fast_transfer;
        } else if (itemCode.equals(CREDIT_CARD_CODE)) {
            return R.drawable.home_icon_credit_card;
        } else if (itemCode.equals(NO_CARD_PAYMENT_CODE)) {
            return R.drawable.home_icon_no_card_payment;
        } else if (itemCode.equals(QR_CODE_CODE)) {
            return R.drawable.home_icon_qr_code;
        } else if (itemCode.equals(INTRE_PAYMENT_CODE)) {
            return R.drawable.home_icon_intre_payment;
        } else {
            return R.drawable.home_icon_receivables;
        }
    }


    public static int getDrawableResIdByFunctionIconName(String iconName, String itemCode) {
        if (TextUtils.isEmpty(iconName) == true){
            return -1;
        }
        if (iconName.equals(COLLECT_MONEY_ICON_CODE)) {
            return R.drawable.home_icon_receivables;
        } else if (iconName.equals(SCAN_PAYMENT_ICON_CODE)) {
            return R.drawable.home_icon_scanner_code_pay;
        } else if (iconName.equals(MONG_HOO_ICON_CODE)) {
            return R.drawable.loan_credit_icon;
        } else if (iconName.equals(HONG_SHOP_ICON_CODE)) {
            return R.drawable.home_icon_market;
        } else if (iconName.equals(LOAN_PACKAGE_ICON_CODE)) {
            return R.drawable.home_icon_loan_package;
        } else if (iconName.equals(STOCK_FUND_ICON_CODE)) {
            return R.drawable.home_open_account_aop;
        } else if (iconName.equals(QQ_IM_ICON_CODE)) {
            return R.drawable.home_icon_qq_consultation;
        } else if (iconName.equals(GATHER_APP_ICON_CODE)) {
            return R.drawable.home_icon_all_funciton;
        } else if (iconName.equals(JIEAN_ICON_CODE)) {
            return R.drawable.jiean;
        } else if (iconName.equals(MOBILE_RECHARGE_ICON_CODE)) {
            return R.drawable.home_icon_phone_chongzhi;
        } else if (iconName.equals(LOAN_ICON_CODE)) {
            return R.drawable.home_icon_loan;
        } else if (iconName.equals(FAST_TRANSFER_ICON_CODE)) {
            return R.drawable.home_icon_fast_transfer;
        } else if (iconName.equals(CREDIT_CARD_ICON_CODE)) {
            return R.drawable.home_icon_credit_card;
        } else if (iconName.equals(NO_CARD_PAYMENT_ICON_CODE)) {
            return R.drawable.home_icon_no_card_payment;
        } else if (iconName.equals(QR_CODE_ICON_CODE)) {
            return R.drawable.home_icon_qr_code;
        } else if (iconName.equals(INTRE_PAYMENT_ICON_CODE)) {
            return R.drawable.home_icon_intre_payment;
        } else {
            return R.drawable.home_icon_intre_payment;
        }
    }

    public static Class<?> getClazzByItemCode(String itemCode) {

        if (itemCode.equals(COLLECT_MONEY_CODE)) {
            //刷卡收款
            return MainActivity.class;
        } else if (itemCode.equals(SCAN_PAYMENT_CODE)) {
            //扫码支付
            return ScannerCodePayActivity.class;
        } else if (itemCode.equals(QR_CODE_CODE)) {
            //码上付
            return ScannerCodePayActivity.class;
        } else if (itemCode.equals(MONG_HOO_CODE)) {
            //代换信用卡
            return ShowLoanHtmlActivity.class;
        } else if (itemCode.equals(HONG_SHOP_CODE)) {
            //在线商城
            return ShowMarketHtmlActivity.class;
        } else if (itemCode.equals(LOAN_PACKAGE_ICON_CODE)) {
            return null;
        } else if (itemCode.equals(STOCK_FUND_CODE)) {
            //证券开户
            return ShowHtmlActivity.class;
        } else if (itemCode.equals(QQ_IM_CODE)) {
            return AllFunctionActivity.class;
        } else if (itemCode.equals(GATHER_APP_CODE)) {
            return AllFunctionActivity.class;
        } else if (itemCode.equals(JIEAN_CODE)) {
            return JieAnHtmlActivity.class;
        } else if (itemCode.equals(MOBILE_RECHARGE_CODE)) {
            return ShowHtmlActivity.class;
        } else if (itemCode.equals(NO_CARD_PAYMENT_CODE)) {
            return ShowHtmlActivity.class;
        } else if (itemCode.equals(LOAN_CODE)) {
            return ShowHtmlActivity.class;
        } else if (itemCode.equals(FAST_TRANSFER_CODE)) {
            return SuperTransferAccounts.class;
        } else if (itemCode.equals(CREDIT_CARD_CODE)) {
            return SuperTransferAccounts.class;
        } else if (itemCode.equals(INTRE_PAYMENT_CODE)) {
            return IntrePaymentHtmlActivity.class;
        }
        return AllFunctionActivity.class;
    }

    public static boolean isExistComponent(String itemCode) {
        if (itemCode.equals(COLLECT_MONEY_CODE)) {
            //刷卡收款
            return true;
        } else if (itemCode.equals(SCAN_PAYMENT_CODE)) {
            //扫码支付
            return true;
        } else if (itemCode.equals(QR_CODE_CODE)) {
            //码上付
            return true;
        } else if (itemCode.equals(MONG_HOO_CODE)) {
            //代换信用卡
            return true;
        } else if (itemCode.equals(HONG_SHOP_CODE)) {
            //在线商城
            return true;
        } else if (itemCode.equals(LOAN_PACKAGE_ICON_CODE)) {
            return true;
        } else if (itemCode.equals(STOCK_FUND_CODE)) {
            //证券开户
            return true;
        } else if (itemCode.equals(QQ_IM_CODE)) {
            return true;
        } else if (itemCode.equals(GATHER_APP_CODE)) {
            return true;
        } else if (itemCode.equals(JIEAN_CODE)) {
            return true;
        } else if (itemCode.equals(MOBILE_RECHARGE_CODE)) {
            return true;
        } else if (itemCode.equals(NO_CARD_PAYMENT_CODE)) {
            return true;
        } else if (itemCode.equals(LOAN_CODE)) {
            return true;
        } else if (itemCode.equals(LOAN_PACKAGE_CODE)) {
            return true;
        } else if (itemCode.equals(FAST_TRANSFER_CODE)) {
            return true;
        } else if (itemCode.equals(CREDIT_CARD_CODE)) {
            return true;
        } else if (itemCode.equals(MY_BASIC_INFO_CODE)) {
            return true;
        } else if (itemCode.equals(MY_QUALIFICATION_INFO_CODE)) {
            return true;
        } else if (itemCode.equals(MY_COLLECT_CARD_MANAGEMENT_CODE)) {
            return true;
        } else if (itemCode.equals(MY_COLLECT_LIMIT_CODE)) {
            return true;
        } else if (itemCode.equals(MY_COLLECT_FLOW_CODE)) {
            return true;
        } else if (itemCode.equals(MY_SWIPE_SELECT_CODE)) {
            return true;
        } else if (itemCode.equals(MY_USER_NOTICE_CODE)) {
            return true;
        } else if (itemCode.equals(MY_T0_QUALIFICATION_CODE)) {
            return true;
        } else if (itemCode.equals(MY_ID_Cardate_CODE)) {
            return true;
        } else if (itemCode.equals(MY_ID_Cardate_CODE)) {
            return true;
        } else if (itemCode.equals(INTRE_PAYMENT_CODE)) {
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return "FunctionInfo{" +
                "itemId='" + itemId + '\'' +
                ", title='" + title + '\'' +
                ", iconResId=" + Arrays.toString(iconResId) +
                ", iconUrl='" + iconUrl + '\'' +
                ", cls=" + cls +
                ", index=" + index +
                ", showModule=" + showModule +
                ", type='" + type + '\'' +
                '}';
    }

    public static HashMap<String, FunctionInfo> getFunctionInfos(Context context) {
        DataBaseComponentModel dbModel = new DataBaseComponentModel(context);
        List<ComponentItemBean> list = dbModel.queryComponentList();
        HashMap<String, FunctionInfo> map = new HashMap<String, FunctionInfo>();
        for (ComponentItemBean component : list) {
//            HPLog.i(HPLog.YL_TAG, "component getFunctionInfos:" + component.toString());
            String functionID = component.getItemCode();
            String functionTitle = component.getItemTitle();
            String functionIconName = component.getIconName();
            String functionType = component.getItemType();
            if (TextUtils.isEmpty(functionIconName) == true){
                continue;
            }
            int functionIconResId = getDrawableResIdByFunctionIconName(functionIconName, functionID);
            Class<?> functionClazz = getClazzByItemCode(functionID);
            map.put(functionID, new FunctionInfo(functionID, functionTitle, new int[]{functionIconResId}, functionClazz, functionType));
        }
        map.put(MY_BASIC_INFO_CODE, new FunctionInfo(MY_BASIC_INFO_CODE, "基本信息", new int[]{R.drawable.icon_my_info}, BaseInfoActivity.class));
        map.put(MY_QUALIFICATION_INFO_CODE, new FunctionInfo(MY_QUALIFICATION_INFO_CODE, "资质信息", new int[]{R.drawable.icon_my_qual}, QualificationInfoActivity.class));
        map.put(MY_COLLECT_CARD_MANAGEMENT_CODE, new FunctionInfo(MY_COLLECT_CARD_MANAGEMENT_CODE, "收款卡管理", new int[]{R.drawable.icon_my_cards}, BankCardManagerActivity.class));
        map.put(MY_COLLECT_LIMIT_CODE, new FunctionInfo(MY_COLLECT_LIMIT_CODE, "收款限额", new int[]{R.drawable.icon_my_quota}, TransferCashLimitManagementActivity.class));
        map.put(MY_COLLECT_FLOW_CODE, new FunctionInfo(MY_COLLECT_FLOW_CODE, "收款流水", new int[]{R.drawable.icon_my_turnover}, QueryBillsActivity.class));
        map.put(MY_SWIPE_SELECT_CODE, new FunctionInfo(MY_SWIPE_SELECT_CODE, "刷卡器连接", new int[]{R.drawable.icon_my_device}, ConnectSwiperActivity.class));
        map.put(MY_USER_NOTICE_CODE, new FunctionInfo(MY_USER_NOTICE_CODE, "用户通知", new int[]{R.drawable.my_notices}, NoticeActivity.class));
        map.put(MY_T0_QUALIFICATION_CODE, new FunctionInfo(MY_T0_QUALIFICATION_CODE, "提现资质", new int[]{R.drawable.icon_my_t0}, T0QualificationActivity.class));
        map.put(MY_ID_Cardate_CODE, new FunctionInfo(MY_ID_Cardate_CODE, "证件补传", new int[]{R.drawable.icon_my_qual}, IDCardateActivity.class));
        return map;
    }

}
